import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useLocalStorage } from '@vueuse/core';

import { toast } from '@/utils/toastHelper';

export function useMemoList() {
  const list = useLocalStorage('memo-list', []);
  const loading = ref(false);
  const finished = ref(true);
  const router = useRouter();

  function deleteMemo(id) {
    list.value = list.value.filter((memoItem) => memoItem.id !== id);

    toast('成功删除');
  }

  return {
    list,
    loading,
    finished,
    deleteMemo,
    router,
  };
}
